package castledefense.logic.buildings;

import castledefense.logic.Map;
import castledefense.logic.Selectable;

public class Building implements Selectable {
	protected Map map;
	protected int cellX, cellY;
	protected float posX, posY; 
	protected int size;
	protected double halfSize;
	protected int cost;
	protected int buildingType;
	protected int elementType;
	protected boolean isSelected = false;
	protected double initialLife = 300;
	protected double life = initialLife;

	public Building(Map map, int posX, int posY, int size, int type) {
		this.map = map;
		this.posX = posX * Map.cellWidth;
		this.posY = posY * Map.cellWidth;
		this.cellX = posX;
		this.cellY = posY;
		this.size = size;
		this.halfSize = 0.5*(double)size;
		this.buildingType = type;
	}

	public boolean contains(double x, double y) {
		final int ix = (int) x;
		final int iy = (int) y;
		return cellX <= ix && cellX + size > ix && cellY <= iy
				&& cellY + size > iy;
	}
	
	public int getElementType(){
		return elementType;
	}
	public void setElementType(int type) {
		elementType = type;
	}

	public boolean contains(int x, int y) {
		return cellX <= x && cellX + size > x && cellY <= y
				&& cellY + size > y;
	}

	public void setSelected(boolean value) {
		isSelected = value;
	}

	public boolean isSelected() {
		return isSelected;
	}

	public void damage(double damage) {
		life -= damage;
	}

	public float getRenderingX() {
		return posX;
	}

	public float getRenderingY() {
		return posY;
	}

	public double getCenterX() {
		return cellX + halfSize;
	}

	public double getCenterY() {
		return cellY + halfSize;
	}

	public int getCellX() {
		return cellX;
	}

	public int getCellY() {
		return cellY;
	}

	public int getSize() {
		return size;
	}

	public int getCost() {
		return cost;
	}

	public int getBuildingType() {
		return buildingType;
	}

	public void update(int deltaTime) {

	}

	public void upgrade(int type) {

	}

	public boolean getIsSelected() {
		return isSelected;
	}
}
